package com.neuedu.corejava.ch9;

public class Student {

	private int id;
	private String name;
	
	public Student() {
		super();
	}
	
	
	
	public Student(int id, String name) {
		super();
		this.id = id;
		this.name = name;
	}


	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}


//什么时候需要重写equals方法
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Student) {
			// 判断是否为同一个对象
			boolean ret=this.hashCode()==obj.hashCode();
			Student s=(Student)obj;
			
			ret = ret || (id==s.getId() && name.equals(s.getName()));
					
			return ret;
			
		}else {
			return false;
		}
		
	}


//什么时候需要重写toString方法
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return " Student[ id=" + id+ ",name=" + name +"]";
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

}
